package ch.exm.storm.conditions.arguments;

import java.util.ArrayList;
import java.util.List;

public class ExpressionEvaluatedArgument implements EvaluatedArgument {

	private Argument sourceArgument;
	
	private String evaluatedPart;
	
	private List<Invocation> nonRelationalInvocations = new ArrayList<Invocation>();
	
	public ExpressionEvaluatedArgument(Argument sourceArgument) {
		this.sourceArgument = sourceArgument;
	}
	
	public boolean isFullyEvaluated() {
		return nonRelationalInvocations.isEmpty();
	}
	
	public void addNonRelationalInvocations(Invocation invocation) {
		nonRelationalInvocations.add(invocation);
	}

	public String getEvaluatedPart() {
		return evaluatedPart;
	}

	public void setEvaluatedPart(String evaluatedPart) {
		this.evaluatedPart = evaluatedPart;
	}

	public Argument getSourceArgument() {
		return sourceArgument;
	}

	public Object evaluateNonRelationalPart(Object object) {
		for (Invocation invocation : nonRelationalInvocations) object = invocation.invokeOn(object);
		return object;
	}

	@Override
	public String toString() {
		return sourceArgument.toString();
	}
}
